# CMake 最低版本号要求
cmake_minimum_required (VERSION 2.8)
# 项目信息
project (pyfree-sysmgr)
#
if(WIN32)
    message(STATUS "windows compiling...")
    add_definitions(-D_PLATFORM_IS_WINDOWS_)
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
    # SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
    set(WIN_OS true)
else(WIN32)
    message(STATUS "linux compiling...")
    add_definitions( -D_PLATFORM_IS_LINUX_)
    add_definitions("-Wno-invalid-source-encoding")
	  # add_definitions("-O2")
    set(UNIX_OS true)
    set(_DEBUG true)
    
endif(WIN32)

#
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../demo-project/sysmgr)

# 指定源文件的目录,并将名称保存到变量
SET(source_h
    #func
    ${PROJECT_SOURCE_DIR}/../common/pfunc.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_code.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_format.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_str.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_ip.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_time.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_print.h
    #
    ${PROJECT_SOURCE_DIR}/../common/Log.h
    ${PROJECT_SOURCE_DIR}/../common/File.h
    ${PROJECT_SOURCE_DIR}/../common/Mutex.h
    ${PROJECT_SOURCE_DIR}/../common/strchange.h
    ${PROJECT_SOURCE_DIR}/../common/cJSON.h
    #sys
    ${PROJECT_SOURCE_DIR}/../common/appexitio.h
    ${PROJECT_SOURCE_DIR}/../common/version.h
    ${PROJECT_SOURCE_DIR}/../common/License.h
    #conf
    ${PROJECT_SOURCE_DIR}/conf/conf.h
    ${PROJECT_SOURCE_DIR}/conf/xml_io.h
    ${PROJECT_SOURCE_DIR}/conf/datadef.h
    ${PROJECT_SOURCE_DIR}/conf/business_def.h
    ${PROJECT_SOURCE_DIR}/conf/svc_control.h
    #conf
    ${PROJECT_SOURCE_DIR}/src/appinfo.h
    #
    ${PROJECT_SOURCE_DIR}/mqtt_io_aliyun/AliyunIotFunc.h
    ${PROJECT_SOURCE_DIR}/mqtt_io_aliyun/ConsumerMqttAliyun.h
    ${PROJECT_SOURCE_DIR}/mqtt_io_aliyun/ProducerMqttAliyun.h
    ${PROJECT_SOURCE_DIR}/mqtt_io_aliyun/IOToAliyun.h
    #http_servlet
    ${PROJECT_SOURCE_DIR}/http_servlet/http_servlet.h
    ${PROJECT_SOURCE_DIR}/http_servlet/master_service.h

  )
  
SET(source_cpp
    #func
    ${PROJECT_SOURCE_DIR}/../common/pfunc.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_code.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_format.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_str.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_ip.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_time.cpp
    #
    ${PROJECT_SOURCE_DIR}/../common/Log.cpp
    ${PROJECT_SOURCE_DIR}/../common/File.cpp
    ${PROJECT_SOURCE_DIR}/../common/Mutex.cpp
    ${PROJECT_SOURCE_DIR}/../common/strchange.cpp
    ${PROJECT_SOURCE_DIR}/../common/cJSON.c
    #sys
    ${PROJECT_SOURCE_DIR}/../common/appexitio.cpp
    ${PROJECT_SOURCE_DIR}/../common/version.cpp
    ${PROJECT_SOURCE_DIR}/../common/License.cpp
    #
    ${PROJECT_SOURCE_DIR}/conf/xml_io.cpp
    ${PROJECT_SOURCE_DIR}/conf/business_def.cpp
    ${PROJECT_SOURCE_DIR}/conf/svc_control.cpp
    #
    ${PROJECT_SOURCE_DIR}/mqtt_io_aliyun/AliyunIotFunc.cpp
    ${PROJECT_SOURCE_DIR}/mqtt_io_aliyun/ConsumerMqttAliyun.cpp
    ${PROJECT_SOURCE_DIR}/mqtt_io_aliyun/ProducerMqttAliyun.cpp
    ${PROJECT_SOURCE_DIR}/mqtt_io_aliyun/IOToAliyun.cpp
    #http_servlet
    ${PROJECT_SOURCE_DIR}/http_servlet/http_servlet.cpp
    ${PROJECT_SOURCE_DIR}/http_servlet/master_service.cpp
    #
	  ${PROJECT_SOURCE_DIR}/src/main.cpp
  )
  
#头文件目录
include_directories(${PROJECT_SOURCE_DIR}/../common)
include_directories(${PROJECT_SOURCE_DIR}/conf)
include_directories(${PROJECT_SOURCE_DIR}/mqtt_io_aliyun)
include_directories(${PROJECT_SOURCE_DIR}/http_servlet)
include_directories(${PROJECT_SOURCE_DIR}/src)
#
include_directories(${PROJECT_SOURCE_DIR}/../acl-master/lib_acl/include)
include_directories(${PROJECT_SOURCE_DIR}/../acl-master/lib_acl_cpp/include)
include_directories(${PROJECT_SOURCE_DIR}/../acl-master/lib_protocol/include)
include_directories(${PROJECT_SOURCE_DIR}/../iot_aliyun/sdk-impl)

if (${UNIX_OS})

execute_process(COMMAND /bin/bash ../build.sh)

include_directories(${PROJECT_SOURCE_DIR}/../svc_common)

SET(source_cpp_win
  ${PROJECT_SOURCE_DIR}/../svc_common/linuxSVC.cpp
)

add_definitions(
  "-W"
  "-fPIC"
  "-Wall"
  # "-Wall -g"
  "-Werror"
  "-Wshadow"
  "-Wformat"
  "-Wpointer-arith"
  "-D_REENTRANT"
  "-D_USE_FAST_MACRO"
  "-Wno-long-long"
  "-Wuninitialized"
  "-D_POSIX_PTHREAD_SEMANTICS"
  "-DACL_PREPARE_COMPILE"
  "-Wno-unused-parameter"
  "-fexceptions"
  )
  set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")

link_directories(
  "${PROJECT_SOURCE_DIR}/../acl-master"
  "${PROJECT_SOURCE_DIR}/../iot_aliyun/linux_lib/x64"
)
# 指定生成目标
add_executable(pyfree-sysmgr ${source_h} ${source_cpp} ${source_cpp_win})
#link
target_link_libraries(pyfree-sysmgr 
  -lpthread -pthread -lz -lrt -ldl
  libacl_all.a
  libiot_sdk.a libiot_platform.a libiot_tls.a -Bstatic -lgcov
)

endif()

if (${WIN_OS})

include_directories(${PROJECT_SOURCE_DIR}/../svc_common)

SET(source_cpp_win
  ${PROJECT_SOURCE_DIR}/../svc_common/WinSVC.cpp
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4819")

add_definitions(
  "-D_CRT_SECURE_NO_WARNINGS"
  "-D_WINSOCK_DEPRECATED_NO_WARNINGS"
  "-DNO_WARN_MBCS_MFC_DEPRECATION"
  "-DWIN32_LEAN_AND_MEAN"
)

link_directories(
  "${PROJECT_SOURCE_DIR}/../acl-master/dist/lib/win64"
  "${PROJECT_SOURCE_DIR}/../iot_aliyun/win_lib/x64"
  )

if (CMAKE_BUILD_TYPE STREQUAL "Debug")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/../demo-project/sysmgr)
# 指定生成目标
add_executable(pyfree-sysmgrd ${source_h} ${source_cpp} ${source_cpp_win})

target_link_libraries(pyfree-sysmgrd
  nafxcwd.lib
  LIBCMTD.lib
  lib_acl_vc2015d.lib lib_acl_cpp_vc2015d.lib lib_protocol_vc2015d.lib
  iot_sdkd.lib
)

else(CMAKE_BUILD_TYPE)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/../demo-project/sysmgr)
# 指定生成目标
add_executable(pyfree-sysmgr ${source_h} ${source_cpp} ${source_cpp_win})

target_link_libraries(pyfree-sysmgr
  nafxcw.lib
  LIBCMT.lib
  lib_acl_vc2015.lib lib_acl_cpp_vc2015.lib lib_protocol_vc2015.lib
  iot_sdk.lib
)

endif (CMAKE_BUILD_TYPE)

endif()

